# Create your views here.
from eport.pages.models import Page
from eport.essays.models import Essay
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.contrib.auth.models import User
from django.template import RequestContext
from django import forms
from django.core.urlresolvers import reverse
from django.contrib.sitemaps import Sitemap

def view_page(request, page_url):
	try:
		page = Page.objects.get(page_uri=page_url)
		essay = Essay.objects.all().order_by('creation_date')
		
	except Page.DoesNotExist:
		if (request.user.is_staff):
			valid = True
		else:
			valid = False
		return render_to_response('pages/404.html', {"page_url":page_url,  'valid':valid}, context_instance = RequestContext(request))
	if (request.user.is_staff):
		valid = True
	else:
		valid = False
	if(page.id == 5):
		disp = True
	else:
		disp = False
	video = False
	if(page.id == 4):
		video = True
	
	context = {
		'page' : page,
		'valid' : valid,
		'essay' : essay,
		'disp' : disp,
		'video' : video,
	}

	return render_to_response(
		'pages/view.html', 
		context, 
		context_instance = RequestContext(request)
	)
def index(request):
	page = Page.objects.get(page_uri='index')
	if (request.user.is_staff):
		valid = True
	else:
		valid = False
	context = {
		'page' : page,
	}
	return render_to_response(
		'pages/view.html', 
		context, 
		context_instance = RequestContext(request)
	)
class PageSitemap(Sitemap):
	changefreq = "weekly"
	priority = 0.5
	def items(self):
		return  Page.objects.all()
	def lastmod(self, obj):
		return obj.creation_date
